package com.koron.device.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.common.core.util.CodeTools;
import com.koron.device.bean.SKksCode;
import com.koron.device.mapper.SKksCodeMapper;
import com.koron.device.service.SKksCodeService;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * kks分类编码字典(SKksCode)表服务实现类
 *
 * @author makejava
 * @since 2023-06-27 16:06:59
 */
@Service
public class SKksCodeServiceImpl implements SKksCodeService {

    /**
     * 通过ID查询单条数据
     *
     * @return 实例对象
     */
    @Override
    public SKksCode queryByName(String name) {
        return ADOConnection.runTask(factory ->{
            SKksCode sKksCode = factory.getMapper(SKksCodeMapper.class).queryByName(name);
            return sKksCode;
        },SKksCode.class);
    }

    @Override
    public PageInfo getPage(SKksCode sKksCode) {
        PageHelper.startPage(sKksCode.getPage(),sKksCode.getPageSize());
        List list1 = ADOConnection.runTask( factory -> {
            List<SKksCode> list = factory.getMapper(SKksCodeMapper.class).queryAllByLimit(sKksCode);
            return list;
        }, List.class);
        return new PageInfo<>(list1);
    }

    /**
     * 新增数据
     *
     * @param sKksCode 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(SKksCode sKksCode) {
        return ADOConnection.runTask( factory ->{
            sKksCode.setId(CodeTools.getCode32());
            int i = factory.getMapper(SKksCodeMapper.class).insert(sKksCode);
            return i;
        },Integer.class);
    }

    /**
     * 修改数据
     *
     * @param sKksCode 实例对象
     * @return 实例对象
     */
    @Override
    public int update(SKksCode sKksCode) {
        return ADOConnection.runTask( factory ->{
            int i = factory.getMapper(SKksCodeMapper.class).update(sKksCode);
            return i;
        },Integer.class);
    }

    /**
     * 通过主键删除数据
     *
     * @return 是否成功
     */
    @Override
    public int deleteById(String id) {
        return ADOConnection.runTask( factory ->{
            int i = factory.getMapper(SKksCodeMapper.class).deleteById(id);
            return i;
        },Integer.class);
    }
}
